/*
 * Copyright (c) 2011.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.skavookie.expressions.java;

import org.skavookie.expressions.*;
import org.skavookie.expressions.*;
import org.skavookie.expressions.*;
import org.skavookie.expressions.*;
import org.skavookie.expressions.Expr;
import org.skavookie.expressions.MinusExpr;
import org.skavookie.expressions.PlusExpr;
import org.skavookie.expressions.TimesExpr;
import org.skavookie.expressions.NegateExpr;
import org.skavookie.expressions.ExprVisitor;
import org.skavookie.expressions.NumericExprVisitor;
import org.skavookie.expressions.IntegralExprVisitor;
import org.skavookie.expressions.FractionalExprVisitor;
import scala.math.Numeric;
import scala.reflect.Manifest;

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 6/2/11
 * Time: 12:18 PM
 * To change this template use File | Settings | File Templates.
 */
public abstract class NumericWrapper<T,V extends NumericExprVisitor> extends ExprWrapper<T,V> {

    protected NumericWrapper(Expr<T> expr) {
        super(expr);
    }

    protected abstract Numeric ops();
    protected abstract Manifest manifest();
    protected abstract NumericWrapper<T,V> pack(Expr<T> expr);

    public static <T,V extends NumericExprVisitor> NumericWrapper<T,V> plus(NumericWrapper<T,V> lhs, NumericWrapper<T,V> rhs) {
        return lhs.pack(new PlusExpr<T>(lhs, rhs, lhs.ops()));
    }

    public static <T,V extends NumericExprVisitor> ExprWrapper<T,V> minus(NumericWrapper<T,V> lhs, NumericWrapper<T,V> rhs) {
        return lhs.pack(new MinusExpr<T>(lhs, rhs, lhs.ops()));
    }

    public static <T,V extends NumericExprVisitor> ExprWrapper<T,V> times(NumericWrapper<T,V> lhs, NumericWrapper<T,V> rhs) {
        return lhs.pack(new TimesExpr<T>(lhs, rhs, lhs.ops()));
    }

    public static <T,V extends NumericExprVisitor> ExprWrapper<T,V> negate(NumericWrapper<T,V> x) {
        return x.pack(new NegateExpr<T>(x, x.ops()));
    }
}
